Imports Microsoft.VisualBasic
Imports System.Collections.Generic

Namespace My
    Public Structure DBBoolean
        Public Value As Boolean

        Public Shared Mappings As New Dictionary(Of Boolean, String)

        Shared Sub New()
            Mappings.Add(True, "Y")
            Mappings.Add(False, "N")
        End Sub

        Sub New(ByVal b As Boolean)
            Me.Value = b
        End Sub

        Sub New(ByVal b As String)
            Select Case b.ToLower()
                Case "y", "true"
                    Me.Value = True
                Case Else
                    Me.Value = False
            End Select
        End Sub

        Public ReadOnly Property DBValue() As String
            Get
                Return Mappings(Me.Value)
            End Get
        End Property

        Public Shared DBTrue As New DBBoolean(True)
        Public Shared DBFalse As New DBBoolean(False)

        Shared Operator =(ByVal a As DBBoolean, ByVal b As DBBoolean) As Boolean
            If a.Value = b.Value Then
                Return True
            Else
                Return False
            End If
        End Operator

        Shared Operator <>(ByVal a As DBBoolean, ByVal b As DBBoolean) As Boolean
            Return Not (a = b)
        End Operator
    End Structure
End Namespace
